package com.logistics.version.controller;

import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.aspect.annotation.Pager;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import com.logistics.version.entity.model.VersionPager;
import com.logistics.version.entity.model.VersionSave;
import com.logistics.version.service.VersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("lgs/version")
public class VersionController {

    @Autowired
    private VersionService versionService;

    /**
     * 查找版本列表分页
     * @param param
     * @return
     */
    @PostMapping("pager")
    @LoggerListener(businessName = "分页查询版本列表", methodName = LoggerMethod.SEARCH)
    public ResponseEntity pager(@RequestBody VersionPager param){
        return ResponseUtil.success(versionService.pager(param));
    }

    /**
     * 查找版本详细
     * @param id
     * @return
     */
    @GetMapping("detail/{id}")
    @LoggerListener(businessName = "查找版本详细", methodName = LoggerMethod.SEARCH)
    public ResponseEntity detail(@PathVariable("id") String id){
        return ResponseUtil.success(versionService.detail(id));
    }

    /**
     * 保存版本
     * @param save
     * @return
     */
    @PutMapping("save")
    @LoggerListener(businessName = "保存版本", methodName = LoggerMethod.SAVE)
    public ResponseEntity save(@RequestBody VersionSave save){
        versionService.save(save);
        return ResponseUtil.success();
    }

    @DeleteMapping("remove/{ids}")
    @LoggerListener(businessName = "删除版本", methodName = LoggerMethod.DELETE)
    public ResponseEntity remove(@PathVariable("ids") String ids) throws MessageException {
        versionService.remove(ids);
        return ResponseUtil.success();
    }

    /**
     * 查找最大版本
     * @return
     */
    @GetMapping("max")
    public ResponseEntity maxVersion(){
        return ResponseUtil.success(versionService.maxVersion());
    }
}
